//二叉树的左视图
function leftView(node){
    if(!node) return null
    const queue = [node]
    const res = []
    while(queue.length){
        let len = queue.length
        for(let i = 0; i < len; i++) {
            let node = queue.shift()
            if (i === 0) res.push(node.val)
            if (node.left) queue.push(node.left)
            if (node.right) queue.push(node.right)
        }
    }
    return res
}

//测试案例
let node = {
    val: 1,
    left: {
        val: 2,
        left: {
            val: 4
        },
        right: {
            val: 5
        }
    },
}

console.log(leftView(node))
